package com.ruoyi.index.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.ruoyi.index.domain.FhIndexPostinfoDetail;
import com.ruoyi.index.mapper.FhIndexPostinfoDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 渔获详情Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class FhIndexPostinfoDetailService {

    @Autowired
    private  FhIndexPostinfoDetailMapper fhIndexPostinfoDetailMapper;

    public  List<FhIndexPostinfoDetail> selectListByPostId(Long postInfoId) {
        return fhIndexPostinfoDetailMapper.selectListByPostId(postInfoId);
    }


    /**
     * 查询渔获详情
     *
     * @param id 渔获详情主键
     * @return 渔获详情
     */
    public FhIndexPostinfoDetail selectById(Integer id) {
        return fhIndexPostinfoDetailMapper.selectById(id);
    }


    /**
     * 查询渔获详情列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 渔获详情
     */
    public List<FhIndexPostinfoDetail> selectList(FhIndexPostinfoDetail query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<FhIndexPostinfoDetail> qw = new QueryWrapper<>();
        Long postinfoId = query.getPostinfoId();
        if (postinfoId != null) {
            qw.eq("postinfo_id", postinfoId);
        }
        Long fishId = query.getFishId();
        if (fishId != null) {
            qw.eq("fish_id", fishId);
        }
        Double weight = query.getWeight();
        if (weight != null) {
            qw.eq("weight", weight);
        }
        Double length = query.getLength();
        if (length != null) {
            qw.eq("length", length);
        }
        LocalDateTime crateTime = query.getCrateTime();
        if (crateTime != null) {
            qw.eq("crate_time", crateTime);
        }
        return fhIndexPostinfoDetailMapper.selectList(qw);
    }

    /**
     * 新增渔获详情
     *
     * @param fhIndexPostinfoDetail 渔获详情
     * @return 结果
     */
    public int insert(FhIndexPostinfoDetail fhIndexPostinfoDetail) {
//        fhIndexPostinfoDetail.setDelFlag(0);
        return fhIndexPostinfoDetailMapper.insert(fhIndexPostinfoDetail);
    }

    /**
     * 修改渔获详情
     *
     * @param fhIndexPostinfoDetail 渔获详情
     * @return 结果
     */
    public int update(FhIndexPostinfoDetail fhIndexPostinfoDetail) {
        return fhIndexPostinfoDetailMapper.updateById(fhIndexPostinfoDetail);
    }

    /**
     * 批量删除渔获详情
     *
     * @param ids 需要删除的渔获详情主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return fhIndexPostinfoDetailMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除渔获详情信息
     *
     * @param id 渔获详情主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return fhIndexPostinfoDetailMapper.updateDelFlagByIds(ids);
    }

    public List<FhIndexPostinfoDetail> selectDetailList(FhIndexPostinfoDetail fhIndexPostinfoDetail) {
        return fhIndexPostinfoDetailMapper.selectDetailList(fhIndexPostinfoDetail);
    }
}
